package com.esri.core.io;

import com.tencent.smtt.sdk.TbsListener;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;

/* loaded from: classes.dex */
public class EsriServiceException extends RuntimeException {
    private static final long serialVersionUID = 1;
    int a;
    String b;

    EsriServiceException() {
    }

    public EsriServiceException(String str) {
        super(str);
        this.b = str;
    }

    public EsriServiceException(int i, String str) {
        super(str);
        this.b = str;
        this.a = i;
    }

    public int getCode() {
        return this.a;
    }

    @Override // java.lang.Throwable
    public String getMessage() {
        return this.b;
    }

    public static EsriServiceException fromJson(JsonParser jsonParser) {
        try {
            if (jsonParser.getCurrentToken() != JsonToken.START_OBJECT) {
                return null;
            }
            EsriServiceException esriServiceException = new EsriServiceException();
            while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
                String currentName = jsonParser.getCurrentName();
                jsonParser.nextToken();
                if ("code".equals(currentName)) {
                    esriServiceException.a = jsonParser.getIntValue();
                } else if ("message".equals(currentName)) {
                    esriServiceException.b = jsonParser.getText();
                } else if ("details".equals(currentName) && jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                    esriServiceException.b += "\n";
                    while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                        esriServiceException.b += jsonParser.getText() + "\n";
                    }
                }
            }
            return esriServiceException;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static EsriServiceException fromGeotriggerJson(String str) {
        EsriServiceException esriServiceException = new EsriServiceException();
        if (str.contains("\"code\":498")) {
            esriServiceException.a = 498;
        } else {
            esriServiceException.a = TbsListener.ErrorCode.INFO_CODE_BASE;
        }
        int indexOf = str.indexOf("\"message\":");
        String str2 = "";
        while (indexOf > 0) {
            StringBuilder sb = new StringBuilder();
            sb.append(str2);
            int i = indexOf + 10;
            int i2 = indexOf + 11;
            sb.append(str.substring(i, str.indexOf("\"", i2)).replaceAll("\"", ""));
            sb.append("; ");
            str2 = sb.toString();
            indexOf = str.indexOf("\"message\":", i2);
        }
        esriServiceException.b = str2;
        return esriServiceException;
    }
}
